<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>resonr</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="resonk.html" title="resonk" />
    <link rel="next" href="resonx.html" title="resonx" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">resonr</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="resonk.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="resonx.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="resonr"></a>
      <div class="titlepage"></div>
      <a id="IndexResonr" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">resonr</span>
        </h2>
        <p>resonr — 
      A bandpass filter with variable frequency response.
          </p>
      </div>
      <div class="refsect1">
        <a id="idp142321056"></a>
        <h2>Description</h2>
        <p>
      Implementations of a second-order, two-pole two-zero bandpass filter with variable frequency response.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp142362496"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ares <span class="command"><strong>resonr</strong></span> asig, xcf, xbw [, iscl] [, iskip]</pre>
      </div>
      <div class="refsect1">
        <a id="idp142364608"></a>
        <h2>Initialization</h2>
        <p>
      The optional initialization variables for <span class="emphasis"><em>resonr</em></span> are identical to the i-time variables for <a class="link" href="reson.html" title="reson"><em class="citetitle">reson</em></a>.
    </p>
        <p>
      <span class="emphasis"><em>iscl</em></span> (optional, default=0) -- coded scaling factor for resonators. A value of 1 signifies a peak response factor of 1, i.e.  all frequencies other than <span class="emphasis"><em>kcf</em></span> are attenuated in accordance with the (normalized) response curve. A value of 2 raises the response factor so that its overall RMS value equals 1. This intended equalization of input and output power assumes all frequencies are physically present; hence it is most applicable to white noise. A zero value signifies no scaling of the signal, leaving that to some later adjustment (see <a class="link" href="balance.html" title="balance"><em class="citetitle">balance</em></a>). The default value is 0.
    </p>
        <p>
      <span class="emphasis"><em>iskip</em></span> (optional, default=0) -- initial disposition of internal data space. Since filtering incorporates a feedback loop of previous output, the initial status of the storage space used is significant. A zero value will clear the space; a non-zero value will allow previous information to remain. The default value is 0.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp142371600"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>asig</em></span> -- input signal to be filtered
    </p>
        <p>
      <span class="emphasis"><em>xcf</em></span> -- cutoff or resonant frequency of the filter, measured in Hz
    </p>
        <p>
      <span class="emphasis"><em>xbw</em></span> -- bandwidth of the filter (the Hz difference between the upper and lower half-power points)
    </p>
        <p>
      <span class="emphasis"><em>resonr</em></span> and <span class="emphasis"><em>resonz</em></span> are variations of the classic two-pole bandpass resonator (<a class="link" href="reson.html" title="reson"><em class="citetitle">reson</em></a>). Both filters have two zeroes in their transfer functions, in addition to the two poles. <span class="emphasis"><em>resonz</em></span> has its zeroes located at z = 1 and z = -1. <span class="emphasis"><em>resonr</em></span> has its zeroes located at +sqrt(<span class="emphasis"><em>R</em></span>) and -sqrt(<span class="emphasis"><em>R</em></span>), where <span class="emphasis"><em>R</em></span> is the radius of the poles in the complex z-plane. The addition of zeroes to <span class="emphasis"><em>resonr</em></span> and <span class="emphasis"><em>resonz</em></span> results in the improved selectivity of the magnitude response of these filters at cutoff frequencies close to 0, at the expense of less selectivity of frequencies above the cutoff peak.
    </p>
        <p>
      <span class="emphasis"><em>resonr</em></span> and <span class="emphasis"><em>resonz</em></span> are very close to constant-gain as the center frequency is swept, resulting in a more efficient control of the magnitude response than with traditional two-pole resonators such as <span class="emphasis"><em>reson</em></span>.
    </p>
        <p>
      <span class="emphasis"><em>resonr</em></span> and <span class="emphasis"><em>resonz</em></span> produce a sound that is considerably different from <span class="emphasis"><em>reson</em></span>, especially for lower center frequencies; trial and error is the best way of determining which resonator is best suited for a particular application.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp142385120"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the resonr and resonz opcodes. It uses the file <a class="ulink" href="examples/resonr.csd" target="_top"><em class="citetitle">resonr.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp142386992"></a>
          <p class="title">
            <strong>Example 754. Example of the resonr and resonz opcodes.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in    No messages</span>
-odac           -iadc     -d     <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o resonr.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="op">/</span><span class="op">*</span> Written by Sean Costello <span class="op">*</span><span class="op">/</span>
 <span class="comment">; Orchestra file for resonant filter sweep of a sawtooth-like waveform. </span>
  <span class="comment">; The outputs of reson, resonr, and resonz are scaled by coefficients</span>
  <span class="comment">; specified in the score, so that each filter can be heard on its own</span>
  <span class="comment">; from the same instrument.</span>

  <span class="ohdr">sr</span> <span class="op">=</span> 44100
  <span class="ohdr">kr</span> <span class="op">=</span> 4410
  <span class="ohdr">ksmps</span> <span class="op">=</span> 10
  <span class="ohdr">nchnls</span> <span class="op">=</span> 1
  
<span class="oblock">instr</span> 1
  
  idur     <span class="op">=</span>        p3
  ibegfreq <span class="op">=</span>        p4                              <span class="comment">; beginning of sweep frequency</span>
  iendfreq <span class="op">=</span>        p5                              <span class="comment">; ending of sweep frequency</span>
  ibw      <span class="op">=</span>        p6                              <span class="comment">; bandwidth of filters in Hz</span>
  ifreq    <span class="op">=</span>        p7                              <span class="comment">; frequency of gbuzz that is to be filtered</span>
  iamp     <span class="op">=</span>        p8                              <span class="comment">; amplitude to scale output by</span>
  ires     <span class="op">=</span>        p9                              <span class="comment">; coefficient to scale amount of reson in output</span>
  iresr    <span class="op">=</span>        p10                             <span class="comment">; coefficient to scale amount of resonr in output</span>
  iresz    <span class="op">=</span>        p11                             <span class="comment">; coefficient to scale amount of resonz in output</span>
  
 <span class="comment">; Frequency envelope for reson cutoff</span>
  kfreq    <span class="opc">linseg</span> ibegfreq, idur <span class="op">*</span> .5, iendfreq, idur <span class="op">*</span> .5, ibegfreq
  
 <span class="comment">; Amplitude envelope to prevent clicking</span>
  kenv     <span class="opc">linseg</span> 0, .1, iamp, idur <span class="op">-</span> .2, iamp, .1, 0
  
 <span class="comment">; Number of harmonics for gbuzz scaled to avoid aliasing</span>
  iharms   <span class="op">=</span>        (<span class="ohdr">sr</span><span class="op">*</span>.4)<span class="op">/</span>ifreq
  
  asig     <span class="opc">gbuzz</span> 1, ifreq, iharms, 1, .9, 1      <span class="comment">; "Sawtooth" waveform</span>
  ain      <span class="op">=</span>        kenv <span class="op">*</span> asig                     <span class="comment">; output scaled by amp envelope</span>
  ares     <span class="opc">reson</span> ain, kfreq, ibw, 1
  aresr    <span class="opc">resonr</span> ain, kfreq, ibw, 1
  aresz    <span class="opc">resonz</span> ain, kfreq, ibw, 1
  
           <span class="opc">out</span> ares <span class="op">*</span> ires <span class="op">+</span> aresr <span class="op">*</span> iresr <span class="op">+</span> aresz <span class="op">*</span> iresz
  
<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

/* Written by Sean Costello */
<span class="stamnt">f</span>1 0 8192 9 1 1 .25                               <span class="comment">; cosine table for gbuzz generator</span>
  
<span class="stamnt">i</span>1  0 10 1 3000 200 100 4000 1 0 0                <span class="comment">; reson  output with bw = 200</span>
<span class="stamnt">i</span>1 10 10 1 3000 200 100 4000 0 1 0                <span class="comment">; resonr output with bw = 200</span>
<span class="stamnt">i</span>1 20 10 1 3000 200 100 4000 0 0 1                <span class="comment">; resonz output with bw = 200</span>
<span class="stamnt">i</span>1 30 10 1 3000  50 200 8000 1 0 0                <span class="comment">; reson  output with bw = 50</span>
<span class="stamnt">i</span>1 40 10 1 3000  50 200 8000 0 1 0                <span class="comment">; resonr output with bw = 50</span>
<span class="stamnt">i</span>1 50 10 1 3000  50 200 8000 0 0 1                <span class="comment">; resonz output with bw = 50</span>
<span class="stamnt">e</span>


<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp142391328"></a>
        <h2>Technical History</h2>
        <p>
      <span class="emphasis"><em>resonr</em></span> and <span class="emphasis"><em>resonz</em></span> were originally described in an article by Julius O. Smith and James B. Angell.<sup>1</sup> Smith and Angell recommended the <span class="emphasis"><em>resonz</em></span> form (zeros at +1 and -1) when computational efficiency was the main concern, as it has one less multiply per sample, while <span class="emphasis"><em>resonr</em></span> (zeroes at + and - the square root of the pole radius R) was recommended for situations when a perfectly constant-gain center peak was required.
    </p>
        <p>
      Ken Steiglitz, in a later article <sup>2</sup>, demonstrated that <span class="emphasis"><em>resonz</em></span> had constant gain at the true peak of the filter, as opposed to <span class="emphasis"><em>resonr</em></span>, which displayed constant gain at the pole angle. Steiglitz also recommended <span class="emphasis"><em>resonz</em></span> for its sharper notches in the gain curve at zero and Nyquist frequency. Steiglitz's recent book <sup>3</sup> features a thorough technical discussion of <span class="emphasis"><em>reson</em></span> and <span class="emphasis"><em>resonz</em></span>, while Dodge and Jerse's textbook <sup>4</sup> illustrates the differences in the response curves of <span class="emphasis"><em>reson</em></span> and <span class="emphasis"><em>resonz</em></span>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp142400336"></a>
        <h2>References</h2>
        <p>
      </p>
        <div class="orderedlist">
          <ol class="orderedlist" type="1">
            <li class="listitem">
              <p>
            Smith, Julius O. and Angell, James B., "A Constant-Gain Resonator Tuned by a Single Coefficient," <span class="emphasis"><em>Computer Music Journal</em></span>, vol. 6, no. 4, pp. 36-39, Winter 1982.
          </p>
            </li>
            <li class="listitem">
              <p>
            Steiglitz, Ken, "A Note on Constant-Gain Digital Resonators," <span class="emphasis"><em>Computer Music Journal</em></span>, vol. 18, no. 4, pp. 8-10, Winter 1994.
          </p>
            </li>
            <li class="listitem">
              <p>
            Ken Steiglitz, <span class="emphasis"><em>A Digital Signal Processing Primer, with Applications to Digital Audio and Computer Music</em></span>. Addison-Wesley Publishing Company, Menlo Park, CA, 1996.
          </p>
            </li>
            <li class="listitem">
              <p>
            Dodge, Charles and Jerse, Thomas A., <span class="emphasis"><em>Computer Music: Synthesis, Composition, and Performance</em></span>. New York: Schirmer Books, 1997, 2nd edition, pp. 211-214.
          </p>
            </li>
          </ol>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp142408640"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="resonz.html" title="resonz"><em class="citetitle">resonz</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp142410784"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Sean Costello</td>
          </tr>
          <tr>
            <td>Seattle, Washington</td>
          </tr>
          <tr>
            <td>1999</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in Csound version 3.55</p>
        <p>Audio rate parameters introduced in version 6.02</p>
        <p>November 2013.</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="resonk.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="resonx.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">resonk </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> resonx</td>
        </tr>
      </table>
    </div>
  </body>
</html>
